﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Vortex.Wrapper.Direct3D;
using Vortex.Wrapper;
using Vortex.Debugging;

namespace Vortex.Drawing {

	/// <summary>
	/// TargetTexture is implementation of render target for Vortex2D.NET.
	/// It can be used as render target and as common texture. Also target texture is resizable.
	/// </summary>
	public class TargetTexture : BaseTargetTexture {

		/// Initializes a new instance of the <see cref="TargetTexture"/> class with specified size and default opaque pixel format.
		/// </summary>
		/// <param name="width">The width.</param>
		/// <param name="height">The height.</param>
		public TargetTexture(int width, int height) : this(width, height, PixelFormat.Default) {
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="TargetTexture"/> class from size and format parameters.
		/// </summary>
		/// <param name="width">The width of target texture.</param>
		/// <param name="height">The height of target texture.</param>
		/// <param name="format">The format of target texture.</param>
		public TargetTexture (int width, int height, PixelFormat format) : this(width, height, format, false) {
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="TargetTexture"/> class from size and format parameters.
		/// </summary>
		/// <param name="width">The width of target texture.</param>
		/// <param name="height">The height of target texture.</param>
		/// <param name="format">The format of target texture.</param>
		/// <param name="createZSurface">if set to <c>true</c> then Z-buffer surface will be created for this target and Z-Effects will work with it; otherwise Z-Effects will be unavailable.</param>
		public TargetTexture(int width, int height, PixelFormat format, bool createZSurface) {
			InitializeTargetTexture(width, height, format, createZSurface);
		}


		#region IDrawingTarget Members

		/// <summary>
		/// Gets or sets the size of target texture. Note, targets binded to specified context can't be resized.
		/// </summary>
		/// <value>The size of target texture.</value>
		public new Size Size {
			get { return base.Size; }
			set {
				Size currentSize = base.Size;
				//check is size changes, rekick target only if size changes
				if (value.Width != currentSize.Width || value.Height != currentSize.Height) {
					FreeData();
					InitializeTargetTexture(value.Width, value.Height, Format, _createZSurface);
					//invoked resize event
					InvokeSurfaceResizeEvent();
				}
				
			}
		}


		#endregion
	}
}
